package com.ruyiadmin.springboot.common_infrastructure.models;

import com.alibaba.fastjson.JSON;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.springframework.http.HttpStatus;

/**
 * <p>
 * RuYiAdmin统一执行结果
 * </p>
 *
 * @author RuYiAdmin
 * @since 2022-07-14
 */
@AllArgsConstructor
@NoArgsConstructor
@Data
public class ActionResponseResult extends RuYiAdminBaseDomainEntity {
    //Http状态码
    private int httpStatusCode;
    //返回消息
    private String message;
    //返回值
    private Object object;

    //region 反序列化方法

    /**
     * <p>
     * 反序列化方法
     * </p>
     *
     * @param text 字符串
     * @return ActionResult
     */
    public static ActionResponseResult deserializeObject(String text) {
        return JSON.parseObject(text, ActionResponseResult.class);
    }

    //endregion

    public static ActionResponseResult success(Object object) {
        return new ActionResponseResult(HttpStatus.OK.value(), "OK", object);
    }

    public static ActionResponseResult ok(Object object) {
        return new ActionResponseResult(HttpStatus.OK.value(), "OK", object);
    }

    public static ActionResponseResult ok() {
        return new ActionResponseResult(HttpStatus.OK.value(), "OK", "OK");
    }

    public static ActionResponseResult error() {
        return new ActionResponseResult(HttpStatus.INTERNAL_SERVER_ERROR.value(), "ERROR", null);
    }

    public static ActionResponseResult error(String message) {
        return new ActionResponseResult(HttpStatus.INTERNAL_SERVER_ERROR.value(), message, null);
    }

    public static ActionResponseResult badRequest() {
        return new ActionResponseResult(HttpStatus.BAD_REQUEST.value(), "BAD_REQUEST", null);
    }

    public static ActionResponseResult badRequest(String message) {
        return new ActionResponseResult(HttpStatus.BAD_REQUEST.value(), message, null);
    }

    public static ActionResponseResult unauthorized() {
        return new ActionResponseResult(HttpStatus.UNAUTHORIZED.value(), "UNAUTHORIZED", null);
    }

    public static ActionResponseResult unauthorized(String message) {
        return new ActionResponseResult(HttpStatus.UNAUTHORIZED.value(), message, null);
    }

    public static ActionResponseResult forbidden() {
        return new ActionResponseResult(HttpStatus.FORBIDDEN.value(), "FORBIDDEN", null);
    }

    public static ActionResponseResult forbidden(String message) {
        return new ActionResponseResult(HttpStatus.FORBIDDEN.value(), message, null);
    }

    public static ActionResponseResult notFound() {
        return new ActionResponseResult(HttpStatus.NOT_FOUND.value(), "NOT_FOUND", null);
    }

    public static ActionResponseResult notFound(String message) {
        return new ActionResponseResult(HttpStatus.NOT_FOUND.value(), message, null);
    }

    public static ActionResponseResult noContent() {
        return new ActionResponseResult(HttpStatus.NO_CONTENT.value(), "NO_CONTENT", null);
    }

    public static ActionResponseResult noContent(String message) {
        return new ActionResponseResult(HttpStatus.NO_CONTENT.value(), message, null);
    }

    public static ActionResponseResult tooManyRequests() {
        return new ActionResponseResult(HttpStatus.TOO_MANY_REQUESTS.value(), "TOO_MANY_REQUESTS", null);
    }

    public static ActionResponseResult tooManyRequests(String message) {
        return new ActionResponseResult(HttpStatus.TOO_MANY_REQUESTS.value(), message, null);
    }

    public static ActionResponseResult non() {
        return new ActionResponseResult(HttpStatus.OK.value(), "OK", null);
    }
}
